<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('排课规则主列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>年度：</label>
                                <input type="text" name="year"/>
                            </li>
                            <li>
                                <label>学期</label>
                                <select name="semesterId" th:with="type=${@dict.getType('sc_term_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>年级：</label>
                                <select name="gradeId" th:with="type=${@grade.getGradeList()}">
                                    <option value="">所有</option>
                                    <option th:each="grade : ${type}" th:text="${grade.gradeName}" th:value="${grade.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>描述：</label>
                                <input type="text" name="name"/>
                            </li>
                            <div class="row"></div>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="school:courseConfig:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="school:courseConfig:remove">
                    <i class="fa fa-remove"></i> 批量删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="school:courseConfig:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('school:courseConfig:edit')}]];
        var removeFlag = [[${@permission.hasPermi('school:courseConfig:remove')}]];
        var makeFlag = [[${@permission.hasPermi('school:courseConfig:make')}]];
        var prefix = ctx + "school/courseConfig";
        var semesterDatas = [[${@dict.getType('sc_term_type')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "排课规则主",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'Id',
                    visible: false
                },
                {
                    field: 'year', 
                    title: '年',
                    formatter: function(value, row, index) {
                        return value+'年度';
                    }
                },
                {
                    field: 'semesterId', 
                    title: '学期',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(semesterDatas, value);
                    }
                },
                {
                    field: 'gradeId',
                    title: '年级Id',
                    visible:false
                },
                {
                    field: 'gradeName',
                    title: '年级'
                },
                {
                    field: 'name', 
                    title: '描述'
                },
                {
                    field: 'sections', 
                    title: '课数/天'
                },
                {
                    field: 'weeks',
                    title: '周数'
                },
                {
                    field: 'bgDate',
                    title: '开始日期'
                },
                {
                    field: 'edDate',
                    title: '结束日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="copy(\'' + row.id + '\')"><i class="fa fa-copy"></i>复制</a> ');
                        if(row.state==0){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="makeCourse(\'' + row.id + '\')"><i class="fa fa-inbox"></i>课程设定</a>');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="makeAllCourses(\'' + row.id + '\')"><i class="fa fa-list"></i>生成完整课表</a>');
                        }else{
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="clearAllCourses(\'' + row.id + '\')"><i class="fa fa-clear"></i>清除已生成课表</a>');
                        }

                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="makeNodeTime(\'' + row.id + '\')"><i class="fa fa-times-circle"></i>节次时间</a>');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function copy(id) {
            var copyUri = prefix+"/copy/"+id;
            $.ajax({
                type: "get",
                url:copyUri,
                async:false,
                dataType: "json",
                success: function(res){
                    if(res.code === 301){
                        $.modal.alertWarning(res.msg);
                    }else{
                        $.table.search()
                    }
                }
            })
        }
        function makeCourse(id) {
            var urlcheck = prefix+"/checkClasses/"+id;
            $.ajax({
                type: "get",
                url:urlcheck,
                async:false,
                dataType: "json",
                success: function(res){
                    if(res.code === 301){
                        $.modal.alertWarning(res.msg);
                    }else{
                        var url = prefix+"/makeCourse/"+id
                        $.modal.openTab("班级课程设定", url);
                    }
                }
            })
        }

        /**
         *  清除已生成的课表
         */
        function clearAllCourses(id) {
            var copyUri = prefix+"/clearAllCourses/"+id;
            $.ajax({
                type: "get",
                url:copyUri,
                async:false,
                dataType: "json",
                success: function(res){
                    if(res.code === 301){
                        $.modal.alertWarning(res.msg);
                    }else{
                        $.table.search()
                    }
                }
            })
        }

        /**
         *  清除已生成的课表
         */
        function makeAllCourses(id) {
            var copyUri = prefix+"/makeAllCourses/"+id;
            $.ajax({
                type: "get",
                url:copyUri,
                async:false,
                dataType: "json",
                success: function(res){
                    if(res.code === 301||res.code === 500){
                        $.modal.alertWarning(res.msg);
                    }else{
                        $.table.search()
                    }
                }
            })
        }

        function makeNodeTime(id) {
            var url = prefix+"/makeCourseTime/"+id
            $.modal.openTab("课程时间设定", url);
        }
    </script>
</body>
</html>